import { _decorator, BoxCollider, Component, ICollisionEvent, Node } from "cc";
import { PlayMovement } from "./PlayMovement";
const { ccclass, property } = _decorator;

@ccclass("PlayerCollision")
export class PlayerCollision extends Component {
  start() {
    let collider = this.node.getComponent(BoxCollider);
    collider.on("onCollisionEnter", this.onCollisionEnter, this);
    //重点触发器
     collider.on("onTriggerEnter", this.onTriggerEnter, this);
  }
  onDestroy() {
    let collider = this.node.getComponent(BoxCollider);
    collider.off("onCollisionEnter", this.onCollisionEnter, this);
     collider.off("onTriggerEnter", this.onTriggerEnter, this);
  }
  onTriggerEnter(event: ICollisionEvent) {
    console.log("hit");
    //禁用掉我们的移动脚本
    if (event.otherCollider.node.name == "EndPoit") {
      // let movemonent = this.node.getComponent(PlayMove);
      // movemonent.enabled = false;
      console.log("you win")
    }
  }
  onCollisionEnter(event: ICollisionEvent) {
    console.log("hit");
    //禁用掉我们的移动脚本
    if (event.otherCollider.node.name == "Obstacle") {
      let movemonent = this.node.getComponent(PlayMovement);
      movemonent.enabled = false;
    }
  }
  update(deltaTime: number) {}
}
